@{
    ViewBag.Title = "js在线加密解密(eval方法)工具";
    ViewBag.keywords = "js加密,js解密,加密解密工具,在线加密解密,eval加密,eval解密,eval方法加密解密,在线JavaScript加密解密,js在线加密解密工具";
    ViewBag.description = "这款js加密解密工具可实现基于eval方法的加密与解密功能，用户可将js代码加密成eval方法执行形式的代码，也可将eval方法加密过的代码进行解密操作。并且提供了在线运行js代码的功能";
    var host = Appsettings.app("BaseFile:HostUrl");
}
<div class="layui-row layui-form layui-form-pane">
    <div class="layui-elem-quote">
        这款聊天内容加密解密工具可实现针对聊天内容自定义暗号进行加密与解密的功能，加密与解密的聊天内容可以是中英文、字母、数字及特殊符号等。
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">内容：</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" id="content" name="content" rows="8" lay-verify="required" autocomplete="off" class="layui-textarea">
var showmsg="粘贴要加密/解密的javascript代码到这里";
if(1==0){
  alert(showmsg);
}
</textarea>
        </div>
    </div>

    <div class="layui-form-item jsencode">
        <a class="layui-btn jiam">加密</a>
        <a class="layui-btn layui-btn-normal jiem">解密</a>
        <a class="layui-btn layui-btn-danger cle">清空</a>
        <a class="layui-btn layui-btn-primary copy">复制结果</a>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">输出：</label>
        <div class="layui-input-block">
            <textarea placeholder="输出内容" id="outtxt" name="outtxt" rows="8" autocomplete="off" class="layui-textarea"></textarea>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <div><a></a></div>
    </div>
</div>

@section Scripts{
<script type="text/javascript">
    layui.config({ base: '@host/js/' }).use('common',function(){ $=layui.jquery;
            var a = 62;
            function encrypt(content, outtxt) {
                var code = document.getElementById(content).value;
                if (code === undefined || code === '' || code === null) { layer.msg("内容不能为空.", { icon: 2 }); return; }
                code = code.replace(/[\r\n]+/g, '');
                code = code.replace(/'/g, "\\'");
                var tmp = code.match(/\b(\w+)\b/g);
                tmp.sort();
                var dict = [];
                var i, t = '';
                for (var i = 0; i < tmp.length; i++) {
                    if (tmp[i] != t) dict.push(t = tmp[i]);
                }
                var len = dict.length;
                var ch;
                for (i = 0; i < len; i++) {
                    ch = num(i);
                    code = code.replace(new RegExp('\\b' + dict[i] + '\\b', 'g'), ch);
                    if (ch == dict[i]) dict[i] = '';
                }
                document.getElementById(outtxt).value = "eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return'\\\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\\\b'+e(c)+'\\\\b','g'),k[c]);return p}(" + "'" + code + "'," + a + "," + len + ",'" + dict.join('|') + "'.split('|'),0,{}))";
            }
            function num(c) {
                return (c < a ? '' : num(parseInt(c / a))) + ((c = c % a) > 35 ? String.fromCharCode(c + 29) : c.toString(36));

            }
            function cleanup(content, outtxt) {
                document.getElementById(content).value = '';
                document.getElementById(outtxt).value = '';
            }
            function decrypt(content, outtxt) {
                var code = document.getElementById(content).value;
                if (code === undefined || code === '' || code === null) { layer.msg("内容不能为空.", { icon: 2 }); return; }
                code = code.replace(/^eval/, '');
                document.getElementById(outtxt).value = eval(code);
            }

            $(".jsencode .jiam").bind("click", function () {
                encrypt('content', 'outtxt');
            })
            $(".jsencode .jiem").bind("click", function () {
               decrypt('content','outtxt');
            })
         });
</script>
}
